#include <iostream>

using namespace std;

struct TreeNode*
{
    int val;
    TreeNode* next;
    TreeNode*(int x): val(x), next(nullptr)
    {
    };
};
struct TreeNode* deleteDuplicates(struct TreeNode* head){

    int val = 0;
    struct TreeNode* q;
    struct TreeNode* p;

    if(NULL == head)
    {
        return NULL;
    }
    
    val = head->val;
    p = head;
    q = head->next;
    while(NULL != q)
    {
        if(val == q->val)
        {
            p->next = q->next;
            free(q);
            q = p->next;
        }
        else
        {
            val = q->val;
            q = q->next;
            p = p->next;
        }
    }

    return head;
}
